#include <fstream>
#include "txtpara.h"

int getparaINT(string paraname, string filename){
	ifstream parafile;
	int result;
	char ch;
	char tmp[256];
	parafile.open(filename.c_str());
	while(!parafile.eof()){
		string cur_para;
		cur_para="";
		parafile>>ch;
		if(ch=='#'){//skip comments
			parafile.getline(tmp,256);
			parafile>>ch;
		}
		while(ch!='='){
			cur_para+=ch;
			parafile>>ch;
		}
		if(cur_para==paraname){
			parafile>>result;
			break;
		}else{
			parafile.getline(tmp,256);
		}
	}
	parafile.close();
	return result;
}
double getparaDOUBLE(string paraname, string filename){
	ifstream parafile;
	double result;
	char ch;
	char tmp[256];
	parafile.open(filename.c_str());
	while(!parafile.eof()){
		string cur_para;
		cur_para="";
		parafile>>ch;
		if(ch=='#'){//skip comments
			parafile.getline(tmp,256);
			parafile>>ch;
		}
		while(ch!='='){
			cur_para+=ch;
			parafile>>ch;
		}
		if(cur_para==paraname){
			parafile>>result;
			break;
		}else{
			parafile.getline(tmp,256);
		}
	}
	parafile.close();
	return result;
}

string getparaSTRING(string paraname, string filename){
	ifstream parafile;
	string result;
	char ch;
	char tmp[256];
	parafile.open(filename.c_str());
	while(!parafile.eof()){
		string cur_para;
		cur_para="";
		parafile>>ch;
		if(ch=='#'){//skip comments
			parafile.getline(tmp,256);
			parafile>>ch;
		}
		while(ch!='='){
			cur_para+=ch;
			parafile>>ch;
		}
		if(cur_para==paraname){
			parafile>>result;
			break;
		}else{
			parafile.getline(tmp,256);
		}
	}
	parafile.close();
	return result;
}
